package com.yueshop.order.controller;


import com.yueshop.order.entity.OrderEntity;
import com.yueshop.order.entity.OrderReturnApplyEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {


    @Autowired
    RabbitTemplate rabbitTemplate;


    @GetMapping("/sendMq")
    public String sendMq(){
        for (int i = 0; i <10 ; i++) {
            if(i%2==0){
                OrderReturnApplyEntity order = new OrderReturnApplyEntity();
                order.setId((long) i);
                order.setCreateTime(new Date());
                order.setDescription述("退货申请");

                rabbitTemplate.convertAndSend("hello-java-exchange","hello-java",order,new CorrelationData(UUID.randomUUID().toString()));
            }else{
                OrderEntity entity = new OrderEntity();
                entity.setId((long) i);
                rabbitTemplate.convertAndSend("hello-java-exchange","hello-java222",entity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }
}
